using System;
using System.Data;
using System.IO;
using System.Text ;
using System.Web;
using System.Xml;
using System.Web.UI;
using System.Web.UI.WebControls;
 

public partial class XmlTextReaderPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string fileName = Server.MapPath("XmlTextWriter.xml");
        using (XmlTextReader xtr = new XmlTextReader(fileName))
        {
            StringBuilder str = new StringBuilder();
            while (xtr.Read())
            {
                switch (xtr.NodeType)
                {
                case XmlNodeType.XmlDeclaration:
                    str.Append("XML Declaration: <b>");
                    str.Append(xtr.Name);                    
                    str.Append(" ");
                    str.Append(xtr.Value);
                    str.Append("</b><br />");
                    break;
                case XmlNodeType.Element:
                    str.Append("    Element: <b>");
                    str.Append(xtr.Name);
                    str.Append(" ");
                    str.Append(xtr.GetAttribute("ID"));
                    str.Append("</b> <br />");
                    break;
                case XmlNodeType.Text:
                    str.Append(" - Value: <b>");
                    str.Append(xtr.Value);
                    str.Append("</b><br />");
                    break;
                }
             }
             xtr.Close();
             Literal1.Text = str.ToString();
        }
         
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string fileName = Server.MapPath("XmlTextWriter.xml");
        using (FileStream fs = new FileStream(fileName,FileMode.Open))
        {
            XmlTextReader xtr = new XmlTextReader(fs);        
            StringBuilder str = new StringBuilder();
            while (xtr.Read())
            {
                switch (xtr.NodeType)
                {
                    case XmlNodeType.XmlDeclaration:
                        str.Append("XML Declaration: <b>");
                        str.Append(xtr.Name);
                        str.Append(" ");
                        str.Append(xtr.Value);
                        str.Append("</b><br />");
                        break;
                    case XmlNodeType.Element:
                        str.Append("    Element: <b>");
                        str.Append(xtr.Name);
                        str.Append(" ");
                        str.Append(xtr.GetAttribute("ID"));
                        str.Append("</b> <br />");
                        break;
                    case XmlNodeType.Text:
                        str.Append(" - Value: <b>");
                        str.Append(xtr.Value);
                        str.Append("</b><br />");
                        break;
                }
            }
            xtr.Close();
            Literal1.Text = str.ToString();
        }
         
    }
}
